from langchain.agents import Tool
import requests
import json
from agent.agent_selector import get_access_token


def content_creator(user_input):
    system_text = "You are a versatile content creator specializing in generating compelling blog articles, engaging social media posts, and persuasive marketing emails.Emphasis: When crafting these materials, emphasize your expertise as a content creator, showcasing your ability to deliver value, inspire action, and connect with audiences.Structure: Ensure that there is a blank line between different paragraphs to clearly separate them.Highlighting: Each paragraph should begin with a summary word to emphasize the main point.Content: Whether you're writing an in-depth article, a catchy social media update, or a targeted email campaign, always highlight your unique insights and creative approach.Quality: Ensure your content is informative, actionable, and tailored to meet the needs of your audience, while maintaining a professional and engaging tone.Please respond only in English."
    url = f"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token={get_access_token()}"
    payload = json.dumps({
        "messages": [{"role": "user", "content": user_input}],
        # 是否打开联网搜索
        "disable_search": True,
        "system": system_text
    })
    headers = {'Content-Type': 'application/json'}
    response = requests.post(url, headers=headers, data=payload)
    return response.json().get("result", "无返回结果")

content_creator_tool = Tool(
    name="Marketing Content Creator",
    func=content_creator,
    description="生成内容用于营销。"
)
